<?php

/**
 * \file
 * Classe `Time`.
 */

namespace pilar\Entities /* \cond */ ; /* \endcond */
{

/**
 * Membre d'une heure de la journée.
 *
 * \since 10/02/2009
 * \author Salim TALEB <salim.taleb@ecl2010.ec-lyon.fr>
 */
class Time extends Member {

protected function loadDefaultParams() {
 parent::loadDefaultParams();
 
 $this->params->set(array(
  'name' => 'time',
  'caption' => 'heure',
  'genre' => 'she',
  'formClass' => '\\pilar\\SimpleFormMembers\\Time',
  'searchFormClass' => '\\pilar\\SearchFormMembers\\Time'
 ));

 $this->params->define(array(
  'defaultValue' => '' // Valeur par défaut.
 ));
}


protected function initialize() {
 parent::initialize();

 $this->addField(
  new \pilar\Entities\Fields\Time(array(
   'defaultValue' => $this->get('defaultValue')
  ))
 );
}


public function getFieldValueFromFormMember($fm, $f = '') {
 return $fm->H.':'.$fm->I.':'.($fm->get('withSeconds')?$fm->S:'00');
}


public function acceptsFieldValue($fieldName, $value) {
 return preg_match('/^([0-1][0-9]:[0-5][0-9]:[0-5][0-9])$/', $value) == 1 ||
        preg_match('/^(2[0-3]:[0-5][0-9]:[0-5][0-9])$/', $value) == 1;
}


public function getFormFieldValueFromObjectMember($om, $f = '') {
 $ov = $om->get();

 if($ov == '') return '';

	list($H, $I, $S) = explode(':', $ov, 3);

 switch($f) {
  case 'H': return $H; break; 
  case 'I': return $I; break;
  case 'S': return $S; break;
  default: return '??';
 }
}


} // Class.

} // Namespace.

?>
